/**
 * 修改当前用户密码的窗口
 */
define(function(){
	var ChangePwdWindow = Ext.extend(Ext.Window, {
		initComponent: function(){
			Ext.apply(this, {
				title: '修改密码',
			    width: 280,
			    modal: true,
			    resizable: false,
			    bodyStyle:'padding:5px;',
			    buttonAlign:'right',
			    iconCls: 'icon-window',
			    animateTarget: this.animateTarget || cu.getDefaultAnimateTarget(),
			    items:[this.formPanel = this.createForm()],
			    buttons: [
			    	{text: '保存', handler: this.save, iconCls: 'icon-save', scope: this},
			    	{text: '取消', handler: this.close, iconCls: 'icon-close', scope: this}
			    ],
				listeners: {
			    	show: function(){
			    		this.firstFocus();
						cu.bindEnter(this, this.save);
			    	}
			    }
			});
			ChangePwdWindow.superclass.initComponent.call(this);
		},
		save: function(){
			cu.submit({
				form: this.getForm(), 
				url: 'sys/user/changePassword.do',
				success: function(data){
					this.close();
			    	if (lu.isFn(this.callback)){
			    		this.callback.call(this.cbScope, data);
			    	}
				}, 
				scope: this
			});
		},
		firstFocus: function(){
			this.getForm().items.itemAt(0).focus(true, 200);
		},
		getForm: function(){
			return this.formPanel.getForm();
		},
		createForm: function(){
			return new Ext.form.FormPanel({
			    baseCls: 'x-plain',
			    labelWidth: 60,
			    labelPad: 5,
			    labelAlign: "right",
			    defaults: {xtype:'textfield',inputType: 'password', allowBlank: false, anchor:'99%', style:'margin: 0 0 5 5'},
			    items: [{
			        fieldLabel:'原密码',
			        name: 'oldPwd'
			    },{
			        fieldLabel: '新密码',
			        name: 'newPwd',
			        maxLength: 20
			    },{
			    	fieldLabel: '密码确认',			    	
			    	name: 'confirmPwd',
				    maxLength: 20,
			        validator: function(value){
			        	var cmp = this.ownerCt.getForm().findField('newPwd').getValue();
			        	return value == cmp ? true : "两次输入密码不一致";
			        }
			    }]
			});
		}
	});
	return ChangePwdWindow;
});